package com.demo.delivery;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class UserAdapter extends ArrayAdapter<User> {
	private List<User> users;

	public UserAdapter(Context context, List<User> items) {
		super(context, R.layout.app_custom_list, items);
		this.users = items;
	}
	public User getUser(int position) {
		return users.get(position);
	}
	@Override
	public int getCount() {
		return users.size();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		if (v == null) {
			LayoutInflater li = LayoutInflater.from(getContext());
			v = li.inflate(R.layout.app_custom_list, null);
		}

		User app = users.get(position);

		if (app != null) {
			TextView titleText = (TextView) v.findViewById(R.id.numberTxt);

			if (titleText != null)
				titleText.setText(app.getUserName());
			
			Button delivered = (Button) v.findViewById(R.id.delivered);
			delivered.setTag(position);
			
			Button pending = (Button) v.findViewById(R.id.pending);
			pending.setTag(position);

		}

		return v;
	}
}
